package common

import "fmt"

// PlatformError 平台错误
type PlatformError struct {
	Code    string
	Message string
	Cause   error
}

func (e *PlatformError) Error() string {
	if e.Cause != nil {
		return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Cause)
	}
	return fmt.Sprintf("[%s] %s", e.Code, e.Message)
}

// 预定义错误
var (
	ErrPlatformNotSupported = &PlatformError{
		Code:    "PLATFORM_NOT_SUPPORTED",
		Message: "platform not supported",
	}

	ErrInvalidRequest = &PlatformError{
		Code:    "INVALID_REQUEST",
		Message: "invalid request parameters",
	}

	ErrInvalidResponse = &PlatformError{
		Code:    "INVALID_RESPONSE",
		Message: "invalid response from platform",
	}

	ErrTimeout = &PlatformError{
		Code:    "TIMEOUT",
		Message: "request timeout",
	}

	ErrNetwork = &PlatformError{
		Code:    "NETWORK_ERROR",
		Message: "network error occurred",
	}

	ErrAuthentication = &PlatformError{
		Code:    "AUTHENTICATION_ERROR",
		Message: "authentication failed",
	}

	ErrAuthorization = &PlatformError{
		Code:    "AUTHORIZATION_ERROR",
		Message: "authorization failed",
	}

	ErrInternal = &PlatformError{
		Code:    "INTERNAL_ERROR",
		Message: "internal server error",
	}
)
